package cn.wolfcode.luowowo.service.impl;

import cn.wolfcode.luowowo.api.cache.prefix.BasekeyPrefix;
import cn.wolfcode.luowowo.api.cache.prefix.UserInfoKeyPrefix;
import cn.wolfcode.luowowo.api.cache.service.IRedisService;
import cn.wolfcode.luowowo.api.cache.service.IUserInfoRedisService;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserInfoRedisServiceImpl implements IUserInfoRedisService{
    @Autowired
    private IRedisService redisService;

    public void addToken(BasekeyPrefix prefix, String token, UserInfo userInfo) {
        //存入到redis中
        redisService.set(prefix,token,userInfo);
    }

    public UserInfo getUserInfoByToken(UserInfoKeyPrefix prefix, String token) {
        UserInfo userInfo = redisService.get(prefix,token,UserInfo.class);
        if(userInfo != null){
            redisService.expire(prefix,token);
        }
        return userInfo;
    }


    public List<UserInfo> getUserInfoByUserId(UserInfoKeyPrefix prefix, Long id) {
        String key =":"+id;
        return redisService.reversRangeSet(prefix,key,UserInfo.class);


    }

    public void addFollow(UserInfoKeyPrefix followUid, Long id, UserInfo u2) {
        redisService.setFollow(followUid,id,u2);

    }


}
